package com.leyou.trade.web;

import com.leyou.auth.constants.JwtConstants;
import com.leyou.commons.dto.PageDTO;
import com.leyou.trade.dto.OrderDTO;
import com.leyou.trade.dto.OrderDetailsDTO;
import com.leyou.trade.dto.OrderDetailsDTO1;
import com.leyou.trade.dto.SearchParamDTO;
import com.leyou.trade.entity.Order;
import com.leyou.trade.entity.comment;
import com.leyou.trade.entity.OrderDetail;
import com.leyou.trade.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;
    @PostMapping
    public ResponseEntity<Long> createOrder(@RequestBody OrderDTO orderDTO,HttpServletRequest request){
        return ResponseEntity.ok(orderService.createOrder(orderDTO,request));
    }
    @GetMapping("{id}")
    public ResponseEntity<Order> getOrderById(@PathVariable("id")Long id){
        return ResponseEntity.ok(orderService.getById(id));
    }

    /**
     * 定时查询
     * @param orderId
     * @return
     */
    @GetMapping("/status/{id}")
    public ResponseEntity<Integer> queryOrderState(@PathVariable("id") Long orderId){
        return ResponseEntity.ok(orderService.queryOrderState(orderId));
    }

    /**
     * 提醒发货
     */
    @GetMapping("/RemindDelivery/{id}")
    public ResponseEntity<Void> RemindDelivery(@PathVariable("id") Long orderId){
        orderService.RemindDelivery(orderId);
    return ResponseEntity.ok().build();
    }
    /**
     * 确认收货
     */
    @GetMapping("/confirmreceipt/{id}")
    public ResponseEntity<Void> confirmreceipt(@PathVariable("id") Long orderId){
        orderService.confirmreceipt(orderId);
        return ResponseEntity.ok().build();
    }

    /**todo
     * 订单评价
     * @param map
     * @return
     */
    @PostMapping("/comment")
    public ResponseEntity<Boolean> comment(@RequestBody comment comment){
        return ResponseEntity.ok(orderService.comment(comment));
    }

    /**todo
     * 查看评价
     * @param id
     * @return
     */
    @GetMapping("/checkComment")
    public ResponseEntity<Map<String,Object>> checkComment(@RequestParam("id") Long id){
        return ResponseEntity.ok(orderService.checkComment(id));
    }

    /**
     * 查询所有订单
     * @param searchParam 查询条件
     * @return 状态值
     */
    @PostMapping("/findAllOrder")
    public ResponseEntity<PageDTO<OrderDetailsDTO>> queryOrderList(@RequestBody SearchParamDTO searchParam){
        return ResponseEntity.ok(orderService.queryOrderList(searchParam));
    }
/**
     * 查询订单详情
     * @param orderId 查询条件
     * @return 状态值
     */
    @GetMapping("/findDetail")
    public ResponseEntity<OrderDetailsDTO1> queryOrderDetail(@RequestParam("orderId") Long orderId){
        return ResponseEntity.ok(orderService.queryOrderDetail(orderId));
    }


}
